package org.will.java8.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * 1. Integer集合最大最小值
 *
 * @Author wangwei-ww
 * @Date 2018/3/9 17:49
 * @Comment
 */
public class StreamInteger {
    private static void append(StringBuilder sb, Integer i) {
        sb.append(i);
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);

        StringBuilder sb = new StringBuilder();
        list.stream().forEach(i -> append(sb, i));
        System.out.println(sb.toString());

        Optional<Integer> minVal = list.stream().min(Integer::compare);
        if (minVal.isPresent()) {
            System.out.println("minVal is " + minVal.get());
        }
    }
}
